home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / MacGS 2.5.2ß3 / (MacGSLib.π) / macDeviceDLOG.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-17  |  5.8 KB  |  252 lines  |  [TEXT/R*ch]

  1. /* Copyright (C) 1993 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. #include <stdio.h>
  21. #include <stddef.h>
  22. #include "gx.h"                /* for gx_bitmap; includes std.h */
  23. #include "iref.h"
  24. #include "gxdevice.h"
  25. #include "state.h"
  26. #include "gsstate.h"
  27. #include "gmacres.h"
  28. #include "gp_macui.h"
  29.  
  30.  
  31. extern    gx_device  *gx_device_list[];
  32.  
  33. void    DoSetDeviceDialog (void);
  34.  
  35.  
  36. enum
  37. {
  38.     iOKOutline = Cancel + 1,
  39.     iOptions,
  40.  
  41.     __iFirstDeviceDITL__,
  42.     iMacDisplay = __iFirstDeviceDITL__,
  43.     iBitTimer,
  44.     iGIFMono,
  45.     iGIF8Bit,
  46.     iPbm,
  47.     iPbmRaw,
  48.     iPgm,
  49.     iPgmRaw,
  50.     iPpm,
  51.     iPpmRaw,
  52.  
  53.     __iLastDialogItem__
  54. };
  55.  
  56.  
  57. #define CALLBACK(procName, args)                            \
  58. {                                                            \
  59.     if (pGUIProcs /* != (GUIProcPtr) NULL */ &&                \
  60.         pGUIProcs->procName /* != (void) (*) (...) NULL */)    \
  61.     {                                                        \
  62.         callbackStatus = (*pGUIProcs->procName) args;        \
  63.     }                                                        \
  64. }
  65.  
  66. static short        DoSetDeviceDialogPriv (void);
  67.  
  68. static GUIProcPtr    pGUIProcs = (GUIProcPtr) NULL;
  69. static short        lastItem  = 0;
  70. static short        ithDevice;
  71. static char            callbackStatus;
  72.  
  73.  
  74.     void
  75. DoSetDeviceDialog (void)
  76.  
  77. {
  78.     short    item;
  79.  
  80.  
  81.     do
  82.     {
  83.         switch (item = DoSetDeviceDialogPriv ())
  84.         {
  85.             case iOptions:
  86.             {
  87.                 CALLBACK (DoOptionsProc, (iDoDialogAction));
  88.                 break;
  89.             }
  90.         }
  91.  
  92.     } while (item != OK && item != Cancel);
  93.  
  94.     /*...Select the device...*/
  95.  
  96.     if (item == OK)
  97.     {
  98.         if (lastItem != ithDevice)
  99.         {
  100.             Str255    string;
  101.             Str255    psString;
  102.  
  103.  
  104.             NumToString ((long) (lastItem - __iFirstDeviceDITL__), string);
  105.             GetIndString (psString, MACPSSTRS_RES_ID, iMacSetDevice);
  106.             BlockMove ((Ptr) &psString[1], (Ptr) &string[string[0] + 1],
  107.                        (Size) psString[0]);
  108.             string[0] += psString[0];
  109.  
  110.             (void) doRunString (PtoCstr (string));
  111.         }
  112.  
  113.         CALLBACK (DoOptionsProc, (iCommitAction));
  114.     }
  115.     else
  116.     {
  117.         CALLBACK (DoOptionsProc, (iRetractAction));
  118.     }
  119. }
  120.  
  121.  
  122. #define SET_RADIO_BUTTON_VALUE(ithDevice, value)                                \
  123. {                                                                                \
  124.     if (__iFirstDeviceDITL__ <= ithDevice && ithDevice < __iLastDialogItem__)    \
  125.     {                                                                            \
  126.         GetDItem (dialog, ithDevice, &iType, &hItem, &rect);                    \
  127.         if (iType & (ctrlItem | radCtrl))                                        \
  128.             SetCtlValue ((ControlHandle) hItem, value);                            \
  129.     }                                                                            \
  130. }
  131.  
  132.  
  133. #define SET_DEVICE_RADIO_BUTTON(ithDevice)                                        \
  134. {                                                                                \
  135.     if (lastItem != ithDevice)                                                    \
  136.     {                                                                            \
  137.         if ((dev = gs_getdevice (ithDevice - __iFirstDeviceDITL__))                \
  138.                 /* != (gx_device *) NULL */)                                    \
  139.         {                                                                        \
  140.             GUIProcPtr    pOldGUIProcs = pGUIProcs;                                \
  141.                                                                                 \
  142.                                                                                 \
  143.             callbackStatus = kNoOptions;                                        \
  144.                                                                                 \
  145.             pGUIProcs = FindGUIProcs (gs_devicename (dev));                        \
  146.                                                                                 \
  147.             if (pGUIProcs /* != (GUIProcPtr) NULL */ &&                            \
  148.                 pGUIProcs->DoOptionsProc /* != (GUIOptionsProc) NULL */)        \
  149.             {                                                                    \
  150.                 CALLBACK (DoOptionsProc, (iInitDialogAction));                    \
  151.             }                                                                    \
  152.                                                                                 \
  153.             if (callbackStatus & kIsIllegalDrvr)                                \
  154.             {                                                                    \
  155.                 pGUIProcs = pOldGUIProcs;                                        \
  156.             }                                                                    \
  157.             else                                                                \
  158.             {                                                                    \
  159.                 SET_RADIO_BUTTON_VALUE (lastItem , 0);                            \
  160.                 SET_RADIO_BUTTON_VALUE (ithDevice, 1);                            \
  161.                                                                                 \
  162.                 lastItem = ithDevice;                                            \
  163.                                                                                 \
  164.                 GetDItem (dialog, iOptions, &iType, &hItem, &rect);                \
  165.                 if (iType & (ctrlItem | btnCtrl))                                \
  166.                 {                                                                \
  167.                     short    hiliteCode = (callbackStatus & kHaveOptions)        \
  168.                                              ?   0                                \
  169.                                              : 255;                                \
  170.                                                                                 \
  171.                                                                                 \
  172.                     HiliteControl ((ControlHandle) hItem, hiliteCode);            \
  173.                 }                                                                \
  174.             }                                                                    \
  175.                                                                                 \
  176.         }                                                                        \
  177.     }                                                                            \
  178. }
  179.  
  180.  
  181.     short
  182. DoSetDeviceDialogPriv (void)
  183.  
  184. {
  185.     short        item   = Cancel;
  186.     DialogPtr    dialog = GetNewDialog (MACSETDEVICEDLOG, (char *) NULL, (WindowPtr) -1);
  187.  
  188.  
  189.     if (dialog /* != (DialogPtr) NULL */)
  190.     {
  191.         short        iType;
  192.         Handle        hItem;
  193.         Rect        rect;
  194.         gx_device **pDeviceList;
  195.         gx_device  *dev           = (gx_device *) NULL;
  196.         gx_device  *currDev       = gs_currentdevice (igs);
  197.         Boolean        fBreakLoop;
  198.  
  199.  
  200.         pGUIProcs = (GUIProcPtr) NULL;
  201.         lastItem  = 0;
  202.  
  203.         /*...Prep outline field...*/
  204.  
  205.         GetDItem (dialog, iOKOutline, &iType, &hItem, &rect);
  206.  
  207.         if (iType == userItem | itemDisable)
  208.             SetDItem (dialog, iOKOutline, iType, (Handle) drawOutline, &rect);
  209.  
  210.         /*...Establish the default driver...*/
  211.  
  212.         for (pDeviceList = gx_device_list, ithDevice = __iFirstDeviceDITL__;
  213.              *pDeviceList /* != (gx_device *) NULL */;
  214.              pDeviceList++, ithDevice++)
  215.         {
  216.             if (*pDeviceList == currDev)
  217.             {
  218.                 SET_DEVICE_RADIO_BUTTON (ithDevice);
  219.                 break;
  220.             }
  221.         }
  222.  
  223.         /*...Run the modal dialog...*/
  224.  
  225.         ShowWindow (dialog);
  226.  
  227.         for (fBreakLoop = FALSE; !fBreakLoop; )
  228.         {
  229.             ModalDialog ((ProcPtr) NULL, &item);
  230.  
  231.             switch (item)
  232.             {
  233.                 case OK:
  234.                 case Cancel:
  235.                 case iOptions:
  236.                     fBreakLoop = TRUE;
  237.                     break;
  238.  
  239.                 default:
  240.                 {
  241.                     SET_DEVICE_RADIO_BUTTON (item);
  242.                     break;
  243.                 }
  244.             }
  245.         }
  246.  
  247.         DisposDialog (dialog);
  248.     }
  249.  
  250.     return item;
  251. }
  252.